package com.godyao.framework.aop.framework;

import com.godyao.framework.aop.AdvisedSupport;
import com.godyao.framework.aop.framework.support.Cglib2AopProxy;
import com.godyao.framework.aop.framework.support.JdkDynamicAopProxy;

public class ProxyFactory {
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getObject() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            // 无实现接口走cglib代理
            return new Cglib2AopProxy(advisedSupport);
        }
        return new JdkDynamicAopProxy(advisedSupport);
    }
}
